var loginUsername = '198504203'; // "${loginUsername}"; //获得当前登录人员的userName

// @Bind view.onReady
!function(self, arg) {
	var dsCheckTaskAssign = view.id("dsCheckTaskAssign");
	dsCheckTaskAssign.set("parameter", {
		"checkerUid" : loginUsername
	});
	dsCheckTaskAssign.flush();
	
}

//@Bind #dtCheckTaskAssign.onCurrentChange
!function(self,arg,dsCheckTaskAssign,dsCheckBill,btnStartCheck,btnFinishCheck) {
	var assn = dsCheckTaskAssign.getData('#');
	
	dsCheckBill.set("parameter", {
		"checkTaskUid" : assn.get("checkTaskUid")
	});
	dsCheckBill.flush();
	
	if(assn.get("checkTask.checkTaskState") < 207){
		btnStartCheck.set("disabled", false);
		btnFinishCheck.set("disabled", true);
	}else if(assn.get("checkTask.checkTaskState") == 207){
		btnStartCheck.set("disabled", true);
		btnFinishCheck.set("disabled", false);
	}else{
		btnStartCheck.set("disabled", true);
		btnFinishCheck.set("disabled", true);
	}
}

//@Bind #dtCheckBill.onInsert
!function(self,arg,dsCheckTaskAssign) {
	var assn = dsCheckTaskAssign.getData('#');
	var bill = arg.entity;
	bill.set("checkTaskUid", assn.get("checkTaskUid"));
	bill.set("taskUid", assn.get("checkTask.taskUid"));
	bill.set("checkBillState", 0);
	bill.set("checkType", assn.get("checkTask.checkTaskType"));
	bill.set("checkTypeDesc", assn.get("checkTaskTypeDesc"));
	bill.set("checkTask.operationTask.model", assn.get("checkTask.operationTask.model"));
	bill.set("checkTask.operationTask.part.drawingId", assn.get("checkTask.operationTask.part.drawingId"));
	bill.set("checkTask.operationTask.part.partName", assn.get("checkTask.operationTask.part.partName"));
	bill.set("checkTask.operationTask.batchNum", assn.get("checkTask.operationTask.batchNum"));
	bill.set("checkTask.operationTask.operationIdDesc", assn.get("checkTask.operationTask.operationIdDesc"));
	bill.set("checkTask.operationTask.taskName", assn.get("checkTask.operationTask.taskName"));
	bill.set("checkTask.operationTask.planQty", assn.get("checkTask.operationTask.planQty"));
	bill.set("submitQty", assn.get("checkTask.operationTask.planQty"));
	bill.set("actualCheckQty", assn.get("checkTask.operationTask.planQty"));
	bill.set("defectQty", 0);
//	bill.set("checkCount", 1);
	bill.set("defectQtyBeforeCheck", 0);
	bill.set("keyCount", 0);
	bill.set("isStatistic", false);
	bill.set("createTime", new Date());
}

//@Bind #btnGenerateDetail.onClick
!function(self,arg,actionGenerateDetail,dsCheckBill,dsCheckTaskAssign) {
	var checkBill = dsCheckBill.getData('#');
	var assn = dsCheckTaskAssign.getData('#');
	
	actionGenerateDetail.set("parameter", 
			{"checkBillUid" : checkBill.get("uuid"),
		     "operationTaskUid" : assn.get("checkTask.taskUid")});
	actionGenerateDetail.execute();
}


//@Bind #actionGenerateDetail.onSuccess
!function(self,arg,dsCheckTask,dsCheckBill) {
	dsCheckBill.flush();
}






//@Bind #dpCheckTaskType.beforeExecute
!function(self,arg,dsTypesData) {
	dsTypesData.set("parameter", {typeName: "checktasktype"});
	dsTypesData.flush();
}

//检验派工
//@Bind #btnDispatch.onClick
!function(self,arg,dsForm,dispatchAction) {
	var form = dsForm.getData('#');
	if(form.get("checkerUid") == null){
		alert('请选择检验员，然后执行派工操作');
	}else{
		dispatchAction.set("parameter", {"checkerUid" : form.get("checkerUid")});
		dispatchAction.execute();
	}
}

//@Bind #dispatchAction.onGetUpdateData
!function(self,arg) {
	var dgCheckTask = view.id("dgCheckTask");
	var checkTasks = dgCheckTask.get("selection");
	if(checkTasks.length == 0){
		alert("请选择检验任务后，执行派工操作");
	}else{
		arg.data = checkTasks;
	}
}

//@Bind #dispatchAction.onSuccess
!function(self,arg,dsCheckTask,dsCheckTaskAssign) {
	dsCheckTaskAssign.flush();
	dsCheckTask.flush();
}

//取消派工
//@Bind #btnCancelDispatch.onClick
!function(self,arg,cancelDispatchAction) {
	cancelDispatchAction.execute();
}

//@Bind #cancelDispatchAction.onGetUpdateData
!function(self,arg) {
	var dgCheckTaskAssign = view.id("dgCheckTaskAssign");
	var checkTaskAssns = dgCheckTaskAssign.get("selection");
	if(checkTaskAssns.length == 0){
		alert("请选择检验派工记录后，执行取消派工操作");
	}else{
		arg.data = checkTaskAssns;
	}
}

//@Bind #cancelDispatchAction.onSuccess
!function(self,arg,dsCheckTask,dsCheckTaskAssign) {
	dsCheckTaskAssign.flush();
	dsCheckTask.flush();
}


